-------------------------------------------------------------------------------
Sample Name: 3Ddefline

Description: An intriguing program to display math functions in 3D. In addition 
             to stress VB6 graphic capabilities, this sample shows how to use 
             the ScriptControl to evaluate a math expression entered by the 
             user. 

Download URL: http://www.it-lang-vb.net/collab.asp?autore=337&Menu=home
-------------------------------------------------------------------------------

IMPORTANT NOTE
The first step to ensure that you can migrate the VB6 project to VB.NET is 
loading the original project in the Visual Basic 6 IDE, run it to ensure that 
it works fine, that all the required type libraries are installed, and that all 
file paths are correct. 
Regardless of whether you edited the source code in any way, you should save 
the VB6 project: this save operation ensures that the .vbp file includes  
the correct path and version of referenced type libraries. 
After saving the project, it's usually a good idea to compile the VB6 project
to an executable, to detect any VB6 compilation errors that would appear under 
VB.NET as well. 
(If you don't recompile the project VB Migration Partner will display a warning 
when you later load the project.)


This sample shows a common mistake of VB6 programmers in declarating variables.
Take a look of this lines of code in Form1:

Dim dx, dy, lx, j, rs, rsbase As Integer
Dim p, xmx, ymx, xc, yc, y, xj, yj, zj, xx, yy, zz As Single
Dim xpj, ypj, xp1j, yp1j, a, b, cosa, sina, cosp, sinp, x, z, zl, xp, xpl, yp, ypl As Double
Dim xl, yl, xlx, yly, xl1, yl1, xlx1, yly1, ycosa, ysina, ycosp, ysinp, xp1, yp1 As Double


What the developer assumed he is defining a series of integers , singles doubles
variables. 
But you know it is not true in Visual Basic 6 where you have to specify types
for each variables.
The above definition are interpreted in this way:

Dim dx as variant, dy as variant, lx as variant, j as variant, rs as variant, rsbase As Integer

Only last variable takes the type specified at the end of the line. 
The others are considered as variant because variant is the default type used by
VB6 for undeclared variables (More precisely, it depends on the active DefXxx 
directive and is Variant only if no such a directive exist in current file.) 
Because of Variants are not supported in VB.NET, VBMS converts them to Objects 
but adds a warning so that you can spot the probable mistake.
The use of objects type can causes hidden logical errors, as happens in this 
sample. 




You can fix it editing the original code and defining each variable of the right 
type or use a ReplaceStatement pragma for modifying the code that VBMS will 
generate.

That is:

'##ReplaceStatement Dim dx, dy, lx, j, rs, rsbase As System.Int32
Dim dx, dy, lx, j, rs, rsbase As Integer

'##ReplaceStatement Dim p, xmx, ymx, xc, yc, y, xj, yj, zj, xx, yy, zz As System.Single
Dim p, xmx, ymx, xc, yc, y, xj, yj, zj, xx, yy, zz As Single

'##ReplaceStatement Dim xpj, ypj, xp1j, yp1j, a, b, cosa, sina, cosp, sinp, x, z, zl, xp, xpl, yp, ypl As System.Double
Dim xpj, ypj, xp1j, yp1j, a, b, cosa, sina, cosp, sinp, x, z, zl, xp, xpl, yp, ypl As Double

'##ReplaceStatement Dim xl, yl, xlx, yly, xl1, yl1, xlx1, yly1, ycosa, ysina, ycosp, ysinp, xp1, yp1 As System.Double
Dim xl, yl, xlx, yly, xl1, yl1, xlx1, yly1, ycosa, ysina, ycosp, ysinp, xp1, yp1 As Double


Note that this kind of definition is correct in VB.NET.
Each variable will be declare of the type specified at the and of the 
definition line.


Do the same in the DrawFunction method, as below:

Private Sub DrawFunction()
  'draw the function in the Form
  On Error GoTo Errore:
  '##ReplaceStatement Dim x, y As System.Single
  Dim x, y As Single
  'p = precision, distance from two lines
  p = lx / rs
  'draw the iso-level lines: it draws line from the previous point to the
  'point evaluated at the moment
  'it use ScriptControl.Run for evaluate the function added before
  For y = -lx To lx Step 0.5
    ycosp = xc + y * cosp
    ycosa = xc - y * cosa
    ysinp = yc - y * sinp
    ysina = yc - y * sina
    For x = -lx To lx Step p
      xp = -x * cosa + ycosp
      xp1 = -(x + p) * cosa + ycosp
      yp = -x * sina + ysinp + ScriptControl.Run("f", x, y)
      yp1 = -(x + p) * sina + ysinp + ScriptControl.Run("f", x + p, y)
      xl = ycosa + x * cosp
      xl1 = ycosa + (x + p) * cosp
      yl = ysina - x * sinp + ScriptControl.Run("f", y, x)
      yl1 = ysina - (x + p) * sinp + ScriptControl.Run("f", y, x + p)
      'draw line from the previous point to the point evaluated now
      Line (xp, yp)-(xp1, yp1), QBColor(10)
      Line (xl, yl)-(xl1, yl1), QBColor(10)
    Next x
  Next y
  Exit Sub
Errore:
  'if there is an error evaluating the function (as a division by 0)...
  Resume Next
End Sub



VB Migration Partner typically delivers many warnings that are related to 
code analysis as well as suggestions about how you can improve the original 
VB6 code before converting it to VB.NET. 
You can suppress these warnings by adding the following project-level pragmas 
at the top of any of the file that make up the project:

'##project:DisableMessage 0501
